package com.fling;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.fling.device.*;
import com.fling.screen.GameScreen;
import com.fling.screen.MenuScreen;
import com.fling.services.GameServiceInterface;
import com.fling.services.GoogleServices;

public class FlingHero extends Game implements Constants {
	private MenuScreen menu;
	private GameScreen gameScreen;
	private OrthographicCamera camera;
	private Vector2 gravityVec;
	private float gravity;
	private World world;
	private GameServiceInterface leaderboard;
	private GoogleServices services;
	
	
	public FlingHero(){
		services=new GoogleServices();
	}
	
	public FlingHero(GameServiceInterface leaderboard, GoogleServices services){
		this.leaderboard=leaderboard;
		this.services=services;
	}

	@Override
    public void create() {
		Device device;
		switch(Gdx.app.getType()){
		case Android:
			device=new DeviceAndroid(leaderboard);
			break;
		case Desktop:
			device=new DevicePC();
		case iOS:
			device=new DeviceIOS(leaderboard);
		default:
			device=new DevicePC();
			break;
			
		}
        Locator.init(this, device, services);
        camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
		camera.position.set(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2, 0);
		camera.zoom = 1f;
		camera.update();
		
		
		gravity=0f;
		gravityVec=new Vector2(0,gravity);
		world=new World(gravityVec,false);
		Locator.setWorld(world);
		
        gameScreen=new GameScreen(camera, this);
        menu=new MenuScreen(this,camera, leaderboard);
        setScreen(menu);
    }
    
    public void setGravity(float g){
    	gravity=g;
    	gravityVec.set(0, gravity);
    	world.setGravity(gravityVec);
    }

    public GameScreen getGameScreen(){
    	return gameScreen;
    }
    
    public MenuScreen getMenuScreen(){
    	return menu;
    }

    @Override
    public void render() {
        super.render();
    }

    @Override
    public void dispose() {
        super.dispose();
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
    }

    @Override
    public void pause() {
        super.pause();
    }

    @Override
    public void resume() {
        super.resume();
    }
}
